package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import com.sl.au.entity.WholeSetDevice;

/**
 * 
 * @author XH
 * 设备管理备品备件
 *
 */
@Transactional(readOnly = true)
public interface WholeSetDeviceRepository extends JpaRepository<WholeSetDevice, String> {

	/**
	 * 根据查询条件查询数据
	 * @param key
	 * @param pageable
	 * @return
	 */
	@Query(" select w from WholeSetDevice w where w.deviceName like '%'+?1+'%' "
			+ "or w.type like '%'+?1+'%' "
			+ "or w.deviceSize like '%'+?1+'%' ")
    Page<WholeSetDevice> getwholeSet(String key, Pageable pageable);
	
	@Query(" select count(w) from WholeSetDevice w where w.deviceName like '%'+?1+'%' "
			+ "or w.type like '%'+?1+'%' "
			+ "or w.deviceSize like '%'+?1+'%' ")
	long getCount(String key);
	
	//利用设备类型验证是否记录>1
	@Query(" select count(r) from WholeSetDevice r where r.type=?1")
	long getReCount(String type);
	//利用设备类型找到记录
	List<WholeSetDevice>findByType(String type);
	
}
